package com.chuangke.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum OrderStatusEnum {

//	EDIT("0","编制中"),

    ALL("all", "全部"),

    INVALID("0", "已作废"),

    EDIT("1", "编制中"),

    APPROVAL("5", "审批中/工艺主管审核"),

    APPROVAL_SECOND("6", "仿管主管下发"),

    APPROVAL_THIRD("7", "已下发（验真人员验真）"),

    APPROVAL_FOUR("8", "已仿真（工艺人员验证）"),

    COMPLETE("9", "已完成"),

    EDIT_AGAIN("A", "再编辑");

    private String code;
    private String desc;

    OrderStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static Map<String, Map<String, Object>> toMap() {
        OrderStatusEnum[] ary = OrderStatusEnum.values();
        Map<String, Map<String, Object>> enumMap = new HashMap<>();
        for (OrderStatusEnum orderStatusEnum : ary) {
            Map<String, Object> map = new HashMap<>();
            String key = orderStatusEnum.getCode();
            map.put("code", orderStatusEnum.getCode());
            map.put("desc", orderStatusEnum.getDesc());
            enumMap.put(key, map);
        }
        return enumMap;
    }

    public static List<Map<String, String>> toList() {
        OrderStatusEnum[] ary = OrderStatusEnum.values();
        List<Map<String, String>> list = new ArrayList<>();
        for (OrderStatusEnum orderStatusEnum : ary) {
            Map<String, String> map = new HashMap<>();
            map.put("code", orderStatusEnum.getCode());
            map.put("desc", orderStatusEnum.getDesc());
            list.add(map);
        }
        return list;
    }

    public static OrderStatusEnum getEnum(String code) {
        OrderStatusEnum[] arry = OrderStatusEnum.values();
        for (OrderStatusEnum orderStatusEnum : arry) {
            if (orderStatusEnum.getCode().equalsIgnoreCase(code)) {
                return orderStatusEnum;
            }
        }
        return null;
    }

    /**
     * 取枚举的json字符串
     *
     * @return
     */
    public static String getJsonStr() {
        OrderStatusEnum[] enums = OrderStatusEnum.values();
        StringBuilder jsonStr = new StringBuilder("[");
        for (OrderStatusEnum senum : enums) {
            if (!"[".equals(jsonStr.toString())) {
                jsonStr.append(",");
            }
            jsonStr.append("{code:'").append(senum.getCode()).append("',desc:'").append(senum.getDesc()).append("'}");
        }
        jsonStr.append("]");
        return jsonStr.toString();
    }
}
